namespace Day25WebAPI.Data.Migrations
{
    using Day25WebAPI.Data.Models;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<Day25WebAPI.Data.ApplicationDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(Day25WebAPI.Data.ApplicationDbContext context)
        {
            UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(context);
            UserManager<ApplicationUser> manager = new UserManager<ApplicationUser>(store);

            ApplicationUser dan = manager.FindByName("DanMan");

            if (dan == null)
            {
                manager.Create(new ApplicationUser
                {
                    UserName = "DanMan",
                    Email = "DanLikesPeanutButter@jelly.com",
                    Bio = "King of the foreans"
                });

                dan = manager.FindByName("DanMan");
            }

            context.Messages.AddOrUpdate(m => m.Text,
                new Message() { Text = "Hello", Timestamp = DateTime.Now, UserId = dan.Id },
                new Message() { Text = "I just ate peanut butter!!", Timestamp = DateTime.Now, UserId = dan.Id }
            );

            //context.Friends.AddOrUpdate(f => f.FirebaseURL,
            //    new Friend() { FirebaseURL = "https://samplechat.firebaseio-demo.com/users/jack/name.json",  }
            //);
        }
    }
}
